package finalproject.model.rooms;


import finalproject.config.Randomizer;
import finalproject.config.Ressource;
import finalproject.model.items.LectureItem;
import finalproject.model.player.Player;
import finalproject.model.studies.Lecture;
import finalproject.model.studies.Topic;
import finalproject.view.StringManager;

/**
 * The lecture room
 * @author Yassine Tijani
 *
 */
public class LectureRoom extends Room {

	/**
	 * The associated course
	 */
	private Lecture course;


	/**
	 * @param description the room's description
	 * @param course the asssociated course
	 */
	public LectureRoom(String description, Lecture course) {
		super(description,true);
		this.course = course;
	}

	@Override
	public boolean doActivity(Player p) {
		if(course == null)
		{
			return false;
		}
		else if(course.getTopic().equals(Topic.OOP)&& p.getEnergy().getEnergy() != 0)
		{
			p.getItemHolder().getWorkingManager().addKey(new LectureItem(this.course));
			p.getEnergy().setEnergy(p.getEnergy().getEnergy()-1);
			return true;
		}
		else
		{
			return false;
		}
	}

	@Override
	public boolean leavable(Player p)
	{
		if(course == null)
		{
			return true;
		}
		else if (!(course.getTopic().equals(Topic.OOP)))
		{
			return true;
		}
		else if((p.getItemHolder().getWorkingManager().getKeyWith(this.course.getTitle())) != null)

		{
			return true;
		}
		else
		{
			return false;
		}
	}


	public Lecture getCourse() {
		return course;
	}

	public void setCourse(Lecture course) {
		this.course = course;
	}

	@Override
	public boolean prepareActivity(Player p) {
		switch (Randomizer.getRandom().nextInt(4)) {
		case 0:
			this.course = Ressource.otherCourse;
			this.course.setTopic(Topic.BIO);
			return false;
		case 1:
			this.course = Ressource.otherCourse;
			this.course.setTopic(Topic.MATH);
			return false;
		case 2:
			this.course = null;
			return false;
		case 3:
			this.course = p.getBook().getUndoneCourse(Ressource.listCourse);
			return true;
		default:
			break;
		}
		return false;
	}

	@Override
	public String toString()
	{
		if(course == null)
		{
			return super.toString() + " : " + StringManager.getString("emptyroom");
		}
		else if(!course.getTopic().equals(Topic.OOP))
		{
			return super.toString() + " : " + StringManager.getString("othertopic")+ " " + course.getTopic();
		}
		else
		{
			return super.toString() + " : "+ StringManager.getString("oop")+ " " + course.getTitle();
		}
	}

}
